This report contains the analysis of the gapminder dataset and contains the results of the top Countries with the largest life expectancy in Europe. The analysis is based on data from 2007. The report also analyzes how life expectancy changed over the years in Europe.

This report was generated using R and the code to extract the European 2007 data is as follows:

#load tidyverse library
library(tidyverse) # used for data manipulation
library(rmarkdown) # used for paged_table function
library(kableExtra) # used for table
library(ggpubr) #used for ggarrange function 

#read file into R
pop_data <- read_csv("data/gapminder_data.csv")

#create a table with data from European countries in 2007 showing the countries with the largest life expectancy at the top 
euro_data_tbl <- pop_data %>% 
                    filter(continent == "Europe" & year == 2007) %>% 
                    select(-continent, -year) %>% 
                    arrange(desc(lifeExp)) %>% 
                    rename(Country = country, "Population Size" = pop, "Life Expectancy" = lifeExp, "GDP" = gdpPercap)

The results in euro_data_tbl are displayed in the Table below:

euro_data_tbl %>% 
          kable(caption="European countries ordered by greatest life expectancy from 2007 data") %>% 
          kable_styling(bootstrap_options = "striped", full_width = F) %>% 
          scroll_box(width = "100%", height = "200px")
European countries ordered by greatest life expectancy from 2007 data
Country Population Size Life Expectancy GDP
Iceland 301931 81.757 36180.789
Switzerland 7554661 81.701 37506.419
Spain 40448191 80.941 28821.064
Sweden 9031088 80.884 33859.748
France 61083916 80.657 30470.017
Italy 58147733 80.546 28569.720
Norway 4627926 80.196 49357.190
Austria 8199783 79.829 36126.493
Netherlands 16570613 79.762 36797.933
Greece 10706290 79.483 27538.412
Belgium 10392226 79.441 33692.605
United Kingdom 60776238 79.425 33203.261
Germany 82400996 79.406 32170.374
Finland 5238460 79.313 33207.084
Ireland 4109086 78.885 40675.996
Denmark 5468120 78.332 35278.419
Portugal 10642836 78.098 20509.648
Slovenia 2009245 77.926 25768.258
Czech Republic 10228744 76.486 22833.309
Albania 3600523 76.423 5937.030
Croatia 4493312 75.748 14619.223
Poland 38518241 75.563 15389.925
Bosnia and Herzegovina 4552198 74.852 7446.299
Slovak Republic 5447502 74.663 18678.314
Montenegro 684736 74.543 9253.896
Serbia 10150265 74.002 9786.535
Hungary 9956108 73.338 18008.944
Bulgaria 7322858 73.005 10680.793
Romania 22276056 72.476 10808.476
Turkey 71158647 71.777 8458.276

A better way to display this table is with pagination as follows:

paged_table(euro_data_tbl)

Next, the life expectancy in Europe is observed across different years. The aim of this is to check if there was a change in life expectancy over the years. The data used for the life expectancy over the years analysis is the gapminder data and the following data manipulation was performed:

#keep on European data and change year to factor
euro_data_fig <- pop_data %>% 
                    filter(continent == "Europe")  %>% 
                    mutate(year=as_factor(year))

#keep only United Kingdom data and change year to factor
uk_data_fig <- pop_data %>%
                    filter(country == "United Kingdom") %>%
                    mutate(year=as_factor(year))

The life expectancy for Europe over the years is plotted as following:

#Euro plot
euro_plot <- euro_data_fig %>%
                ggplot(mapping=aes(x=year, y=lifeExp)) +
                geom_violin() +
                stat_summary(fun.y = median, geom = "point")

#draw euro plot
euro_plot
Life Expectancy in Europe over the years

Life Expectancy in Europe over the years

 

Comparison of life expectancy from Europe and United Kingdom:

#UK plot
uk_plot <- uk_data_fig %>%
                ggplot(mapping=aes(x=year, y=lifeExp)) +
                geom_point()

#draw euro plot next to UK plot
ggarrange(euro_plot, uk_plot, ncol=2, nrow=1, labels="AUTO")
Life Expectancy in European and UK over the years

Life Expectancy in European and UK over the years

library(DT)
DT::datatable(pop_data, rownames = F, filter = 'top', editable = TRUE, caption = 'Table X: This is a simple caption for the table.', extensions = 'Buttons', options = list(
  dom = 'Bfrtip',
  buttons = c('copy', 'csv', 'exel', 'pdf', 'print')
))